package com.uinnova.springboot.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * 注解标注过滤器
 * 将实现了Filter接口的类标注为过滤器
 * filterName过滤器名称，urlpatterns 指定要过滤的url路径
 */
@WebFilter(filterName = "myFilter",urlPatterns = "/*")
public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("myFilter-过滤器初始化");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("myFilter-过滤器执行过滤操作");
        filterChain.doFilter(request,response);
    }

    @Override
    public void destroy() {
        System.out.println("myFilter-过滤器销毁");

    }
}
